package com.jie.myvhr.controller;

import com.jie.myvhr.bean.Hr;
import com.jie.myvhr.bean.MsgContent;
import com.jie.myvhr.bean.RespBean;
import com.jie.myvhr.bean.SysMsg;
import com.jie.myvhr.service.HrService;
import com.jie.myvhr.service.SysMsgService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author jie
 * @date 2019/6/29 -15:20
 */
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Resource
    private HrService hrService;

    @Resource
    private SysMsgService sysMsgService;


    /**
     * 查询除当前用户外的所有用户列表
     */
    @RequestMapping(value = "/hrs", method = RequestMethod.GET)
    public List<Hr> getAllHr() {
        return hrService.getAllHrExceptAdmin();
    }

    @RequestMapping("/sysmsgs")
    public List<SysMsg> getSysmsg(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                  @RequestParam(value = "size", defaultValue = "10") Integer size) {
        return sysMsgService.getSysMsgByPage(page, size);
    }

    /**
     * 发送系统消息
     */
    @RequestMapping(value = "/nf", method = RequestMethod.POST)
    public RespBean sendNf(MsgContent msg) {
        if (sysMsgService.sendMsg(msg)) {
            return RespBean.ok("发送成功!");
        }
        return RespBean.error("发送失败!");
    }

    /**
     * 修改消息状态
     * @param flag flag?-1:flag
     */
    @PutMapping("/markread")
    public RespBean markread(Long flag){
        if (sysMsgService.markRead(flag)) {
            if (flag == -1) {
                return RespBean.ok("multiple");
            } else {
                return RespBean.ok("single");
            }
        } else {
            if (flag == -1) {
                return RespBean.error("multiple");
            } else {
                return RespBean.error("single");
            }
        }
    }

}
